package com.dkm.orproject.dkmoa.service.serviceimpl;

import com.dkm.orproject.dkmoa.dao.OaRegimeMapper;
import com.dkm.orproject.dkmoa.domain.OaRegime;
import com.dkm.orproject.dkmoa.service.OaRegimeService;
import com.dkm.orproject.utils.utils.IdToobtainUtils;
import com.dkm.orproject.utils.utils.Tools;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 *  @ClassName : OaRegimeServiceImpl  //类名
 *  @Description : OaRegimeAction的service层实现类 //描述
 *  @Author : zmh //作者
 *  @Date: 2020-11-10 09:28  //时间
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class OaRegimeServiceImpl implements OaRegimeService {

    /**
     * 规章制度的mapper对象
     */
    @Resource
    OaRegimeMapper oaRegimeMapper;

    /**
     * id生成工具
     */
    @Autowired
    IdToobtainUtils utils;

    /**
     * 插入一条规章制度
     * @param oaRegime 规章制度对象
     * @return 回调函数
     */
    @Override
    public int insertSelective(OaRegime oaRegime) {
        oaRegime.setPkRegimeId(utils.getNumberId());
        oaRegime.setRegimeCode(Tools.autoClientIdentity(String.valueOf(oaRegimeMapper.findCount())));
        return oaRegimeMapper.insertSelective(oaRegime);
    }

    /**
     * 根据id删除
     * @param pkRegimeId 规则制度id
     * @return 回调函数
     */
    @Override
    public int deleteByPrimaryKey(Long pkRegimeId) {
        return oaRegimeMapper.deleteByPrimaryKey(pkRegimeId);
    }

    /**
     * id查询
     * @param pkRegimeId 规则制度id
     * @return 规则制度模型
     */
    @Override
    public OaRegime selectByPrimaryKey(Long pkRegimeId) {
        return oaRegimeMapper.selectByPrimaryKey(pkRegimeId);
    }

    /**
     * 修改
     * @param oaRegime 规则制度模型
     * @return 回调函数
     */
    @Override
    public int updateByPrimaryKeySelective(OaRegime oaRegime) {
        return oaRegimeMapper.updateByPrimaryKeySelective(oaRegime);
    }

    /**
     * 批量删除
     * @param list list里存入id的集合
     * @return 回调函数
     */
    @Override
    public int deleteAll(List<Long> list) {
        return oaRegimeMapper.deleteAll(list);
    }

    /**
     * 分页查询
     * @param oaRegime 规则制度模型
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @param page 当前页数
     * @param limit 显示的行数
     * @return 查询规则制度模型结果集合
     */
    @Override
    public List<OaRegime> selectAll(OaRegime oaRegime, String startTime, String endTime, Integer page, Integer limit) {
        //分页插件
        PageHelper.startPage(page,limit);
        return oaRegimeMapper.selectAll(oaRegime,startTime,endTime);
    }

    /**
     * 总行数
     * @param oaRegime 规则制度对象
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 总行数
     */
    @Override
    public Long rowCount(OaRegime oaRegime, String startTime, String endTime) {
        return oaRegimeMapper.rowCount(oaRegime,startTime,endTime);
    }
}
